/**
 * @description: 将params code 转成 object
 * @param {string} [queryString]
 * @return {*} object
 */
export const decodeParams = (queryString: string) => {
  const params = new URLSearchParams(queryString);
  // 使用 Array.from 将迭代器转换为数组，然后使用 reduce 将数组转换为对象
  return Array.from(params.entries()).reduce((acc: any, [key, value]) => {
    acc[key] = value;
    return acc;
  }, {});
};

/**
 * @description: 将params code 转成 object
 * @param {objct} [str:string]:any
 * @return {*} string
 */
export const encodeParams = (query: Record<string, any>) => {
  const queryString = "?" + new URLSearchParams(query).toString();
  return queryString;
};

// - "?name=zhangsan&age=12&sex=1"
// { name: "zhangsan", age: "12", sex: "1" };
